package IO.file;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class BinaryFile {
    public static void main(String[] args) {
        File f = new File("demo");
        if (!f.exists()) {
            try {
                f.createNewFile();
                if (!f.canWrite()) {
                    f.setWritable(true);
                }
                FileOutputStream fos = new FileOutputStream(f);
                fos.write(new byte[] { 3, 1, 4, 1, 5, 9, 2, 6 });
                fos.close();
                if (!f.canRead()) {
                    f.setReadable(true);
                }
                FileInputStream fis = new FileInputStream(f);
                int c;
                while ((c = fis.read()) != -1) {
                    System.out.println(c);
                }
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        f.delete();
    }
}
